﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;
namespace project
{
    public partial class AddAdmin : UIForm
    {
        public AddAdmin()
        {
            InitializeComponent();
        }

        private void ClearTextBox()
        {
            uiTextBox1.Text = null;
            uiTextBox2.Text = null;
        }
        private void uiButton1_Click(object sender, EventArgs e)
        {
            // 确认

            string id = uiTextBox1.Text;
            string pwd = uiTextBox2.Text;
            string sqlstr = $"insert into admin_info(admin_number,admin_pwd) " +
                $"values({id},'{pwd}');";


            if (string.IsNullOrEmpty(id) ||
                string.IsNullOrEmpty(pwd))
            {
                MessageBox.Show("存在空数据，请检查后再添加", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int reslut = SqlHelper.ExecuteNonQuery(sqlstr);
            if (reslut == 1)
            {

                MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                ClearTextBox();
            }
            else
            {
                MessageBox.Show("添加失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void uiButton2_Click(object sender, EventArgs e)
        {
            //取消
            this.Close();
        }
    }
}
